package com.zhanghp;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zhanghp
 * @date 2022-08-30 10:22
 */
@Slf4j
public abstract class DinnerTemplate {

    /**
     * 菜肴名称
     */
    protected String cuisineName;

    protected abstract boolean shopping();

    protected abstract void wash();

    protected abstract void cook();

    /**
     * 添加final原因:防止衍生类重写该方法，从而破坏里氏替换原则
     */
    public final void eat() {
        if (shopping()) {
            wash();
            cook();
            log.info("今天的晚饭 {} 已做好，准备吃晚饭", this.cuisineName);
        } else {
            log.info(this.cuisineName + "相关食材已卖完！");
        }
    }
}
